//
//  FixPassTwoVController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/9.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "FixPassTwoVController.h"
#import "LXCInputPasswordView.h"
#import "PayResultView.h"//支付结果视图
@interface FixPassTwoVController ()<LXCInputPasswordViewDelegate,payResultBackBtnDelegate>

{
    NSString *inputTwoPassword;
}

@property (nonatomic, strong)LXCInputPasswordView *passView;
@property (nonatomic, strong)PayResultView *payResultView;

@end

@implementation FixPassTwoVController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _sureBtn.userInteractionEnabled = NO;
    
    if (_payResultView) {
        [_payResultView removeFromSuperview];
    }
    
    _passView = [LXCInputPasswordView inputPasswordViewWithY:115+20];//CGRectGetMaxY(_paLB.frame)
    _passView.delegate = self;
    
    [self.view addSubview:_passView];
    
}
#pragma mark 密码输入框的代理事件
- (void)inputPasswordViewDelegate:(LXCInputPasswordView *)inputPasswordView inputEndWithPassword:(NSString *)inputEndWithPassword {
    
    inputTwoPassword = inputEndWithPassword;
    NSLog(@"---%@",inputEndWithPassword);
    _sureBtn.selected = YES;
    _sureBtn.userInteractionEnabled = YES;
    
}

//小于6位不能确认按钮不能点击
- (void)inputPasswordXiaoYuSix {
    _sureBtn.selected = NO;
    _sureBtn.userInteractionEnabled = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureNaBar];
}
- (void)configureNaBar {
    if ([_type2 isEqualToString:@"支付密码"]) {
        self.navigationItem.title = @"设置支付密码";
        _titleLB.text= @"请再次设置支付密码";
        
    }if ([_type2 isEqualToString:@"提现密码"]) {
        _titleLB.text= @"请再次设置提现密码";
        self.navigationItem.title = @"设置提现密码";
    }
    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhui2"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    
}

- (void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)sureAction:(UIButton *)sender {
    
    if (self.inputOnePassword.integerValue == inputTwoPassword.integerValue) {
        [self SetPayPassword];
    }else{
        [MBProgressHUD showText:@"两次密码输入不一致!!!"];
    }
    
   
    
    
}

- (void)payBackAction:(UIButton *)sender {
    if (_payResultView) {
        [_payResultView removeFromSuperview];
    }
    [self.navigationController popToRootViewControllerAnimated:YES];
}

//设置找回支付密码
//http://bs.m0571.com/mobileapi/public/baishi/?service=Shop_Personal.SetPayPassword&userid=11&payPassword=111111

-(void)SetPayPassword{
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"payPassword":inputTwoPassword,@"mobile":_moblePhoneStr,@"sms_code":_phoneCodeStr,@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    
    [HttpRequest postWithURLString:POST(Shop_SetPayPassword) parameters:parameDic success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        if ([[responseObject objectForKey:@"ret"] integerValue] == 200) {
            NSDictionary *dataDic = [responseObject objectForKey:@"data"];
            if ([[dataDic objectForKey:@"code"] integerValue] == 0) {
                [self getPayResultView];
            }else{
                [MBProgressHUD showText:[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"msg"]]];
            }
            
        }
        
    } failure:^(NSError *error) {
        
    }];

}
-(void)getPayResultView{
    if (_payResultView) {
        [_payResultView removeFromSuperview];
    }
    _payResultView = [[PayResultView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _payResultView.delegate = self;
    _payResultView.imageStr = @"xiugaimima";
    _payResultView.payResultStr = @"设置成功";
    _payResultView.detailStr = @"已成功设置6位支付密码";
    [[UIApplication sharedApplication].keyWindow addSubview:_payResultView];
}


@end
